//
//  GYMyHeadView.m
//  GoodLuck
//
//  Created by 郭为勇 on 2018/2/25.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYMyHeadView.h"

@interface GYMyHeadView ()

@property (weak, nonatomic) IBOutlet UILabel *bgLable;

/** 背景颜色数组 */
@property (nonatomic, strong) NSArray *backgroundColors;

/** 记录当前颜色下表 */
@property (nonatomic, assign) NSInteger currentIndex;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *setBtuTopMarginCons;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *moreBtuMarginCons;

@end
@implementation GYMyHeadView

- (void)awakeFromNib {
    [super awakeFromNib];
    self.currentIndex = 0;
    self.headImageView.layer.cornerRadius = 40;
    self.headImageView.layer.masksToBounds = YES;
    
    //给头像添加一个点击手势
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    [self.headImageView addGestureRecognizer:tapGR];
    
    if (iPhoneX) {
        self.setBtuTopMarginCons.constant = 44;
        self.moreBtuMarginCons.constant = 44;
    }
    //添加一个动画
//    CABasicAnimation *baseAnimation = [CABasicAnimation animation];
//    baseAnimation.keyPath = @"backgroundColor";
//    baseAnimation.fromValue = (__bridge id _Nullable)(RGBColor(250, 145, 72).CGColor);
//    baseAnimation.toValue = (__bridge id _Nullable)(RGBColor(240, 143, 168).CGColor);
//    baseAnimation.duration = 5.0;
//    baseAnimation.repeatCount = MAXFLOAT;
//    baseAnimation.autoreverses = true;
//    [self.layer addAnimation:baseAnimation forKey:nil];
    
    
//    CAKeyframeAnimation *keyBaseAnimation = [CAKeyframeAnimation animation];
//    keyBaseAnimation.values = @[(__bridge id _Nullable)(RGBColor(250, 145, 72).CGColor),
//                                (__bridge id _Nullable)(RGBColor(252, 125, 80).CGColor),
//                                (__bridge id _Nullable)(RGBColor(237, 143, 195).CGColor),
//                                (__bridge id _Nullable)(RGBColor(86, 210, 178).CGColor),
//                                (__bridge id _Nullable)(RGBColor(240, 143, 168).CGColor)
//                                ];
//    keyBaseAnimation.keyPath = @"backgroundColor";
//    keyBaseAnimation.duration = 8.0;
//    keyBaseAnimation.repeatCount = MAXFLOAT;
//    keyBaseAnimation.autoreverses = YES;
    //keyBaseAnimation.timingFunction = kCAMediaTimingFunctionLinear; //kCAMediaTimingFunctionLinear;
    //keyBaseAnimation.keyTimes = @[@2.0,@2.0,@2.0,@2.0,@2.0];//时间点,关键帧  不是执行动画的事假
//    [self.layer addAnimation:keyBaseAnimation forKey:nil];
}

- (void)tap:(UITapGestureRecognizer *)tapGR {
    [self.delegate changedHeadImage];
}

- (CGFloat)getViewHeight {
    return CGRectGetMaxY(self.bgLable.frame);
}

- (IBAction)onClick:(UIButton *)sender {
    
    [self.delegate headViewToBtuClick:sender.tag];
}
@end
